import Mock from 'mockjs2'
import { builder, getQueryParameters } from '../util'

const totalCount = 5705

const serverList = (options) => {
    console.log("options: ")
    console.log(options)
    const parameters = getQueryParameters(options)
    console.log(parameters)
    const result = []
    const pageNo = parseInt(parameters.pageNo)
    const pageSize = parseInt(parameters.pageSize)
    const totalPage = Math.ceil(totalCount / pageSize)
    const key = (pageNo - 1) * pageSize
    const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

    for (let i = 1; i < next; i++) {
        const tmpKey = key + i
        let currentData={}
        let insert=true
        currentData['key']=tmpKey
        currentData['id']=tmpKey
        currentData['no']='No ' + tmpKey,
        currentData['description']='这是一段描述',
        currentData['sportCount']=Mock.mock('@integer(1, 999)'),
        currentData['status']=Mock.mock('@integer(0, 2)'),
        currentData['tarinTime']=Mock.mock('@datetime'),
        currentData['editable']=false
        if(parameters.hasOwnProperty('status')){
          if(currentData['status']!=parameters.status){
            insert=false
          }
        }
        if(insert){
          result.push(currentData)
        }
    }

    return builder({
        pageSize: pageSize,
        pageNo: pageNo,
        totalCount: totalCount,
        totalPage: totalPage,
        data: result
    })
}

const projects = () => {
    return builder({
        'data': [{
                id: 1,
                cover: 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png',
                title: 'Alipay',
                description: '那是一种内在的东西， 他们到达不了，也无法触及的',
                status: 1,
                updatedAt: '2020-07-26 00:00:00'
            },
            {
                id: 2,
                cover: 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png',
                title: 'Angular',
                description: '希望是一个好东西，也许是最好的，好东西是不会消亡的',
                status: 1,
                updatedAt: '2020-07-26 00:00:00'
            },
            {
                id: 3,
                cover: 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png',
                title: 'Ant Design',
                description: '城镇中有那么多的酒馆，她却偏偏走进了我的酒馆',
                status: 1,
                updatedAt: '2020-07-26 00:00:00'
            },
            {
                id: 4,
                cover: 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png',
                title: 'Ant Design Pro',
                description: '那时候我只会想自己想要什么，从不想自己拥有什么',
                status: 1,
                updatedAt: '2020-07-26 00:00:00'
            },
            {
                id: 5,
                cover: 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png',
                title: 'Bootstrap',
                description: '凛冬将至',
                status: 1,
                updatedAt: '2020-07-26 00:00:00'
            },
            {
                id: 6,
                cover: 'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png',
                title: 'Vue',
                description: '生命就像一盒巧克力，结果往往出人意料',
                status: 1,
                updatedAt: '2020-07-26 00:00:00'
            }
        ],
        'pageSize': 10,
        'pageNo': 0,
        'totalPage': 6,
        'totalCount': 57
    })
}

const activity = () => {
    return builder([{
            id: 1,
            user: {
                nickname: '@name',
                avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'
            },
            project: {
                name: '白鹭酱油开发组',
                action: '更新',
                event: '番组计划'
            },
            time: '2020-08-23 14:47:00'
        },
        {
            id: 1,
            user: {
                nickname: '蓝莓酱',
                avatar: 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png'
            },
            project: {
                name: '白鹭酱油开发组',
                action: '更新',
                event: '番组计划'
            },
            time: '2020-08-23 09:35:37'
        },
        {
            id: 1,
            user: {
                nickname: '@name',
                avatar: '@image(64x64)'
            },
            project: {
                name: '白鹭酱油开发组',
                action: '创建',
                event: '番组计划'
            },
            time: '2017-05-27 00:00:00'
        },
        {
            id: 1,
            user: {
                nickname: '曲丽丽',
                avatar: '@image(64x64)'
            },
            project: {
                name: '高逼格设计天团',
                action: '更新',
                event: '六月迭代'
            },
            time: '2020-08-23 14:47:00'
        },
        {
            id: 1,
            user: {
                nickname: '@name',
                avatar: '@image(64x64)'
            },
            project: {
                name: '高逼格设计天团',
                action: 'created',
                event: '六月迭代'
            },
            time: '2020-08-23 14:47:00'
        },
        {
            id: 1,
            user: {
                nickname: '曲丽丽',
                avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'
            },
            project: {
                name: '高逼格设计天团',
                action: 'created',
                event: '六月迭代'
            },
            time: '2020-08-23 14:47:00'
        }
    ])
}

const teams = () => {
    return builder([{
            id: 1,
            name: '科学搬砖组',
            avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'
        },
        {
            id: 2,
            name: '程序员日常',
            avatar: 'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png'
        },
        {
            id: 1,
            name: '设计天团',
            avatar: 'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png'
        },
        {
            id: 1,
            name: '中二少女团',
            avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png'
        },
        {
            id: 1,
            name: '骗你学计算机',
            avatar: 'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png'
        }
    ])
}

const radar = () => {
    return builder([{
            item: '躯干角度',
            '平均值': 70,
            '最大值': 80,
            '最小值': 40
        },
        {
            item: '臀部角度',
            '平均值': 60,
            '最大值': 70,
            '最小值': 40
        },
        {
            item: '手肘角度',
            '平均值': 50,
            '最大值': 60,
            '最小值': 40
        },
        {
            item: '脚踝角度',
            '平均值': 40,
            '最大值': 50,
            '最小值': 35
        },
        {
            item: '大腿角度',
            '平均值': 60,
            '最大值': 70,
            '最小值': 40
        },
        {
            item: '小腿角度',
            '平均值': 70,
            '最大值': 80,
            '最小值': 40
        }
    ])
}

Mock.mock(/\/service/, 'get', serverList)
Mock.mock(/\/list\/search\/projects/, 'get', projects)
Mock.mock(/\/workplace\/activity/, 'get', activity)
Mock.mock(/\/workplace\/teams/, 'get', teams)
Mock.mock(/\/workplace\/radar/, 'get', radar)